package org.shj.book2.chapter03;

import java.util.LinkedList;

public class RequestQueue {

	private final LinkedList<Request> queue = new LinkedList<Request>();
	
	public synchronized Request getRequest() {
		while(queue.size() <=0){
			try{
				wait(); //wait() 会释放当前的锁， 这里是this
			}catch(InterruptedException e){
				
			}
		}
		return queue.removeFirst();
	}
	
	public synchronized void putRequest(Request req){
		queue.add(req);
		notifyAll();
	}
}
